package com.twu.biblioteca;

import java.util.Scanner;

/**
 * Created by venus on 19/09/14.
 */
public class Menu {

    boolean isRun = true;

    public void displayMenu(Library library) {

        while (isRun) {

            //Read from console
            ReaderHelper reader = new ReaderHelper();
            String userInput = reader.getUserInput("Please select one of the following options: \n" +
                    "1) Display Available Books\n" +
                    "2) Search and Check out a book\n" +
                    "3) Return book\n" +
                    "4) Display Available Movies\n" +
                    "5) Search and Check out a movie\n" +
                    "6) Return movie\n" +
                    "7) Show My Details\n" +
                    "8) Quit");

            //Action based on user input
            actionMenu(library, userInput);
        }
    }

    public void actionMenu(Library library, String inputObject) {
        try {
            int inputNumber = Integer.parseInt(inputObject);
            switch (inputNumber) {
                case 1:
                    Library.displayAvailableItems(library.books);
                    break;
                case 2:
                    Library.searchAndCheckoutItem(library.books);
                    break;
                case 3:
                    Library.returnItem(library.books);
                    break;
                case 4:
                    Library.displayAvailableItems(library.movies);
                    break;
                case 5:
                    Library.searchAndCheckoutItem(library.movies);
                    break;
                case 6:
                    Library.returnItem(library.movies);
                    break;
                case 7:
                    Library.displayCurrentUserDetails();
                    break;
                case 8:
                    //quit the program
                    isRun =false;
                    break;

                default:
                    System.out.println("Select a valid option!");
                    break;
            }
        } catch (Exception e) {
            System.out.println("Invalid input. Exception: "+ e);
        }
    }
}
